/********************************************************************************
* File Name:	mainwindow.cpp
* Description:	第3章 实例4：Button Box的实例
* Reference book:《Linux环境下Qt4图形界面与MySQL编程》，机械工业出版社.2012.1
* E_mail: openlinux2011@gmail.com
*
********************************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    Clear = new QPushButton;
    Clear->setText("Clear");
    ui->buttonBox->addButton(Clear,QDialogButtonBox::ActionRole);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_buttonBox_clicked(QAbstractButton* button)
{
    QString str;
    str = ui->textEdit->toPlainText();
    if(button == ui->buttonBox->button(QDialogButtonBox::Ok))
    {
        if(!ui->lineEdit->text().isEmpty())
        {
            str += ui->lineEdit->text()+"\n";
            ui->textEdit->setPlainText(str);
        }
    }
    else if(button == this->Clear)
    {
        ui->textEdit->setPlainText("");
    }
}
